package com.hsh.db;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.hadoop.mapreduce.lib.db.DBWritable;

public class MySqlDBWriteAble implements DBWritable {

	private String[] inputColNames;
	private Map<String,String> values;
	
	@Override
	public void write(PreparedStatement statement) throws SQLException {

	}

	@Override
	public void readFields(ResultSet resultSet) throws SQLException {
		values = new HashMap<String, String>(inputColNames.length);
		for(String column : inputColNames){
			values.put(column, resultSet.getString(column));
		}
	}

	public String[] getInputColNames() {
		return inputColNames;
	}

	public void setInputColNames(String[] inputColNames) {
		this.inputColNames = inputColNames;
	}

	public Map<String, String> getValues() {
		return values;
	}

	public void setValues(Map<String, String> values) {
		this.values = values;
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer(10);
		Iterator<String> ite = values.keySet().iterator();
		while(ite.hasNext()){
			String curr = ite.next();
			sb.append(curr).append(" : ").append(values.get(curr)).append(" : ");
		}
		return sb.substring(0, sb.length()-3);
	}
	
}
